import { TestTableService } from "./testTable.service";
import { Body, Controller, Get, Post, Query } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
import { PaginationPipe } from "src/common/pipes/pagination.pipe";
import { ReqAddUserDto, ReqProTableDto } from "./dto/req-testTable.dto";
import { DataObj } from "src/common/class/data-obj.class";
import { TUser } from "./entities/testTable.entity";

@ApiTags("表格示例")
@Controller("test/table")
export class TestTableController {
  constructor(private readonly testTableServic: TestTableService) {}

  // 分页获取表格数据
  @Get("proTable/getUsers")
  async getProTableList(@Query(PaginationPipe) reqProTableDto: ReqProTableDto) {
    const res = await this.testTableServic.getProTableList(reqProTableDto);
    return DataObj.create(res);
  }

  // 新增用户
  @Post("proTable/addUser")
  async addUser(@Body() reqAddUserDto: ReqAddUserDto) {
    await this.testTableServic.addOrUpdate(reqAddUserDto);
  }

  // 修改用户
  @Post("proTable/editUser")
  async editUser(@Body() reqUpdateUser: TUser) {
    await this.testTableServic.addOrUpdate(reqUpdateUser);
  }

  // 删除用户
  @Post("proTable/deleteUser")
  async deleteUser(@Body("t_user_id") t_user_id: string | number) {
    await this.testTableServic.delete(t_user_id);
  }
}
